package com.hqully.labmanage.controller;

import com.github.pagehelper.PageInfo;
import com.hqully.labmanage.domain.dto.DeviceRecordDTO;
import com.hqully.labmanage.domain.dto.PageDTO;
import com.hqully.labmanage.domain.vo.DeviceRecordVO;
import com.hqully.labmanage.domain.vo.ResultVO;
import com.hqully.labmanage.service.DeviceRecordService;
import com.hqully.labmanage.utils.ResultVOUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 设备使用记录数据接口
 * <p>
 *
 * @author hqully
 * @version 1.0
 * @date 2022-10-08 11:17:19
 */
@Api(tags = {"设备使用记录数据接口"})
@Slf4j
@RestController
@RequestMapping("/api/device-record")
public class DeviceRecordController extends BaseController {

    @Resource
    private DeviceRecordService deviceRecordService;

    @ApiOperation(value = "分页条件查询设备使用记录列表")
    @GetMapping("/page-device-records")
    public ResultVO<PageInfo<DeviceRecordVO>> pageDeviceRecords(PageDTO page, DeviceRecordDTO deviceRecordDTO) {
        PageInfo<DeviceRecordVO> deviceRecordPage = deviceRecordService.pageDeviceRecords(page, deviceRecordDTO);
        return ResultVOUtil.success(deviceRecordPage);
    }

    @ApiOperation(value = "条件查询设备使用记录列表")
    @GetMapping("/list-device-records")
    public ResultVO<List<DeviceRecordVO>> listDeviceRecords(DeviceRecordDTO deviceRecordDTO) {
        List<DeviceRecordVO> deviceRecordList = deviceRecordService.listDeviceRecords(deviceRecordDTO);
        return ResultVOUtil.success(deviceRecordList);
    }

    @ApiOperation(value = "添加设备使用记录")
    @PostMapping("/add-device-record")
    public ResultVO<DeviceRecordDTO> addDeviceRecord(@Validated @RequestBody DeviceRecordDTO deviceRecordDTO) {
        deviceRecordService.addDeviceRecord(deviceRecordDTO);
        return ResultVOUtil.success("添加设备使用记录成功");
    }

    @ApiOperation(value = "更新设备使用记录")
    @PostMapping("/update-device-record")
    public ResultVO<DeviceRecordDTO> updateDeviceRecord(@Validated @RequestBody DeviceRecordDTO deviceRecordDTO) {
        deviceRecordService.updateDeviceRecord(deviceRecordDTO);
        return ResultVOUtil.success("更新设备使用记录成功");
    }

    @ApiOperation(value = "删除设备使用记录")
    @DeleteMapping("/delete-device-record/{id}")
    public ResultVO<DeviceRecordDTO> deleteDeviceRecord(@PathVariable("id") String id) {
        deviceRecordService.deleteDeviceRecordById(id);
        return ResultVOUtil.success("删除设备使用记录成功");
    }

}

